/**
 * 812. 最大三角形面积
 * https://leetcode.cn/problems/largest-triangle-area/
 */

/**
 * @param {number[]} point1
 * @param {number[]} point2
 * @param {number[]} point3
 * @return {number}
 */
function triangleArea(point1, point2, point3) {
  const [x1, y1] = point1;
  const [x2, y2] = point2;
  const [x3, y3] = point3;
  if ((x1 === x2 && x2 === x3) || (y1 === y2 && y2 === y3)) {
    return 0;
  }
  return Math.abs((x1 * y2 + x2 * y3 + x3 * y1 - x1 * y3 - x2 * y1 - x3 * y2) / 2);
}

/**
 * @param {number[][]} points
 * @return {number}
 */
function largestTriangleArea(points) {
  let max = 0;
  for (let i = points.length - 3; i >= 0; i -= 1) {
    for (let j = points.length - 2; j > i; j -= 1) {
      for (let k = points.length - 1; k > j; k -= 1) {
        max = Math.max(max, triangleArea(points[i], points[j], points[k]));
      }
    }
  }
  return max;
}

console.log(largestTriangleArea([[0, 0], [0, 1], [1, 0], [0, 2], [2, 0]]) === 2);
